package net.sxnic.ugr.group.action;

import net.sxnic.ugr.UgrActionSupport;
import net.sxnic.ugr.group.Group;
import net.sxnic.ugr.group.GroupManager;
import net.sxnic.ugr.role.Role;

import org.springframework.beans.factory.annotation.Autowired;

@SuppressWarnings("serial")
public class Delete extends UgrActionSupport {

	@Autowired
	private GroupManager groupManager;

	/**
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	public String execute() throws Exception {
		try {
			checkRoles(Role.SYSTEM_ADMIN);

			Group group = groupManager.get(id);

			group.getRoles().clear();

			authorizationManager.updateGroup(group);
			//
			authorizationManager.deleteGroup(group);

			// 保存删除成功的信息
			msg = "deleteSuccess";

		} catch (Exception e) {
			e.printStackTrace();
		}

		return SUCCESS;
	}

	/**
	 * @param groupManager
	 *            the groupManager to set
	 */
	public void setGroupManager(GroupManager groupManager) {
		this.groupManager = groupManager;
	}
}
